package compilers.symbolTable;

import compilers.AST.types.MyType;
import compilers.AST.types.TypeSpecifier;

public class SymbolTableVariableElement extends SymbolTableElement {
	
	private boolean fConstant;
	private MyType fConstantValue;

	public SymbolTableVariableElement(String identifier, TypeSpecifier type, int nodeId, int lineNr) {
		fIdentifier = identifier;
		fType = type;
		fConstant = false;
		fNodeId = nodeId;
		fLineNr = lineNr;
		fConstantValue = null;
		fMemoryAddress = -1;
	}
	
	public SymbolTableVariableElement(String identifier, TypeSpecifier type, boolean constant, int nodeId, int lineNr) {
		fIdentifier = identifier;
		fType = type;
		fConstant = constant;
		fNodeId = nodeId;
		fLineNr = lineNr;
		fMemoryAddress = -1;
		fConstantValue = null;
	}
	
	public void setConstantValue(MyType value) {
		fConstantValue = value;
	}
	
	public MyType getConstantValue() {
		return fConstantValue;
	}
	
	public boolean isConstant() {
		return fConstant;
	}
	
	public void print(int identLevel) {
		String result = "Variable (" + fIdentifier + ", " + fType.getTypeName();
		if (fConstant) {
			result += ", constant";
		}
		result += ", " + fMemoryAddress + ")";
		println(identLevel, result);
	}
}
